import request from "@/utils/request";

/**
 * 分页查询字典数据
 */
export async function pageDictionaryData(params) {
  const res = await request.get("/system/dictionaryData/page", { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询字典数据列表
 */
export async function listDictionaryData(params) {
  const res = await request.get("/system/dictionaryData", { params });
  if (res.data.code === 200 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加字典数据
 */
export async function addDictionaryData(data) {
  const res = await request.post("/system/dictionaryData", data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取字典数据
 */
export async function showDictionaryData(dict_data_id) {
  const res = await request.get("/system/dictionaryData/" + dict_data_id);
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改字典数据
 */
export async function updateDictionaryData(data) {
  const res = await request.put(
    "/system/dictionaryData/" + data.dict_data_id,
    data,
  );
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

export async function auditDictionaryData(data) {
  const res = await request.put(
    "/system/dictionaryDatashen/" + data.dict_data_id,
    data,
  );
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

export async function pushDictionaryData(data) {
  const res = await request.put(
    "/system/dictionaryDatapush/" + data.dict_data_id,
    data,
  );
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除字典数据
 */
export async function removeDictionaryData(id) {
  const res = await request.delete("/system/dictionaryData/" + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除字典数据
 */
export async function removeDictionaryDataBatch(data) {
  const res = await request.delete("/system/dictionaryData/batch", { data });
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
